﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Text;
using SportsStore.WebUI.Models;

namespace SportsStore.WebUI.HtmlHelpers
{
    public static class PagingHelpers
    {
        public static MvcHtmlString PageLinks( this HtmlHelper html,
            PagingInfo pagingInfo, Func<int, string> pageUrl )
        {
            var result = new StringBuilder();
            for ( int index = 1; index <= pagingInfo.TotalPages; index++ )
            {
                //construct an <a> tag
                TagBuilder tag = new TagBuilder( "a" );
                tag.MergeAttribute( "href", pageUrl( index ) );
                tag.InnerHtml = index.ToString();

                if ( index == pagingInfo.CurrentPage )
                    tag.AddCssClass( "selected" );
                result.Append( tag.ToString() );
            }
            return MvcHtmlString.Create( result.ToString() );
        }
    }
}